home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
10,000 Great Games
/
10,000 Great Games.iso
/
Product
/
66
/
data1.cab
/
Source_Files
/
Src
/
SShot.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-16
|
2KB
|
85 lines
#include "stdafx.h"
void make_screenshot()
{
static int screenshot_number = 1;
// We don't make screen shots in a window
if (inawin)
return;
// Lock surface
DDSURFACEDESC2 srcsurf;
srcsurf.dwSize = sizeof(srcsurf);
while (!draw_ok(screen->Lock(0, &srcsurf, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, 0)));
// Get pointers
BYTE *s = (BYTE *)srcsurf.lpSurface, d[SCREEN_X * SCREEN_Y];
// Copy the image (bottom up)
for (int y = 0; y < SCREEN_Y; y++)
CopyMemory(&d[(SCREEN_Y - 1 - y) * SCREEN_X], &s[y * srcsurf.lPitch], SCREEN_X);
// Unlock the surface
screen->Unlock(0);
// Allocate memory for header
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
BYTE pal[4 * 256];
// Construct bitmap file header
ZeroMemory(&bfh, sizeof(bfh));
bfh.bfType = 0x4d42;
bfh.bfOffBits = sizeof(bfh) + sizeof(bih) + sizeof(pal);
bfh.bfSize = bfh.bfOffBits + sizeof(d);
// Construct bitmap info header
ZeroMemory(&bih, sizeof(bih));
bih.biSize = sizeof(bih);
bih.biWidth = SCREEN_X;
bih.biHeight = SCREEN_Y;
bih.biPlanes = 1;
bih.biBitCount = 8;
bih.biCompression = BI_RGB;
bih.biSizeImage = bfh.bfSize;
bih.biClrUsed = 256;
bih.biClrImportant = 256;
// Construct palette
for (int i = 0; i < 256; i++)
{
pal[4 * i] = rgb_table[i].peBlue;
pal[4 * i + 1] = rgb_table[i].peGreen;
pal[4 * i + 2] = rgb_table[i].peRed;
pal[4 * i + 3] = 0;
}
// Write stuff to file
TRY
{
CFile f(construct("screen%03d.bmp", screenshot_number++), CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive);
f.Write(&bfh, sizeof(bfh));
f.Write(&bih, sizeof(bih));
f.Write(&pal, sizeof(pal));
f.Write(&d, sizeof(d));
}
CATCH(CFileException, e)
{
}
END_CATCH
}